package com.siki.www.clock.vo;

import com.siki.salessystemcommon.entity.ClockInfo;
import com.siki.salessystemcommon.entity.ClockLog;
import com.siki.salessystemcommon.entity.enumeration.*;
import io.swagger.annotations.ApiModelProperty;

import io.swagger.annotations.ApiModel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.springframework.beans.BeanUtils;

import java.util.Objects;
import java.util.Optional;

/**
 * @author Keyvonchen in 2021/6/20
 */
@ApiModel("打卡日志返回VO")
@Getter
@Setter
@ToString
@NoArgsConstructor
public class ClockLogVO {

    @ApiModelProperty("id")
    Long id;

    @ApiModelProperty("连续打卡天数")
    Long clockDays;

    @ApiModelProperty("学号")
    String casId;

    @ApiModelProperty("姓名")

    String name;

    @ApiModelProperty("学院")
    String institute;

    @ApiModelProperty("专业")
    String major;

    @ApiModelProperty("校区")
    String campus;

    /**
     * enum
     */
    @ApiModelProperty("身份类型")
    String cardType;

    @ApiModelProperty("证件号码")
    String cardNumber;

    /**
     * enum
     */
    @ApiModelProperty("人员身份")
    String identifyType;

    @ApiModelProperty("籍贯")
    String nation;

    @ApiModelProperty("近日所在地")
    String recentlyAddress;

    @ApiModelProperty("近日所在地详情")
    String recentlyAddressDetail;

    @ApiModelProperty("经度")
    String lng;

    @ApiModelProperty("纬度")
    String lat;

    @ApiModelProperty("家庭住址")
    String familyAddress;

    @ApiModelProperty("手机号码")
    String phone;

    @ApiModelProperty("紧急联系人")
    String urgentName;

    @ApiModelProperty("紧急联系人联系方式")
    String urgentPhone;

    /**
     * enum
     */
    @ApiModelProperty("身体状况")
    String physicalCondition;

    @ApiModelProperty("是否在莞")
    String inDongGuan;

    @ApiModelProperty("备注")
    String remark;

    @ApiModelProperty("温度")
    String temperature;

    /**
     * enum
     */
    @ApiModelProperty("体温状态")
    String temperatureStatus;

    /**
     * enum
     */
    @ApiModelProperty("人员类型")
    String peopleType;

    @ApiModelProperty("异常情况")
    String alertStatus;

    public ClockLogVO(ClockLog clockLog) {
        Optional.ofNullable(clockLog).ifPresent(ci -> {
            BeanUtils.copyProperties(ci, this);
            this.campus = Optional.ofNullable(ci.getCampus())
                    .map(Objects::toString).orElse(null);
            this.inDongGuan = Optional.ofNullable(ci.getInDongGuan())
                    .filter(i -> i == 1).map(b -> "是").orElse("否");
            this.alertStatus = Optional.ofNullable(ci.getAlertStatus())
                    .filter(i -> i == 1).map(b -> "异常").orElse("正常");
            this.campus = Optional.ofNullable(ci.getCampus())
                    .map(Objects::toString).orElse(null);
            this.cardType = Optional.ofNullable(ci.getCardType())
                    .map(Objects::toString).orElse(null);
            this.identifyType = Optional.ofNullable(ci.getIdentifyType())
                    .map(Objects::toString).orElse(null);
            this.physicalCondition = Optional.ofNullable(ci.getPhysicalCondition())
                    .map(Objects::toString).orElse(null);
            this.temperatureStatus = Optional.ofNullable(ci.getTemperatureStatus())
                    .map(Objects::toString).orElse(null);
            this.peopleType = Optional.ofNullable(ci.getPeopleType())
                    .map(Objects::toString).orElse(null);
            this.temperature = Optional.ofNullable(ci.getTemperature())
                    .map(Objects::toString).orElse("0.0");
        });
    }
}
